#encoding:utf-8
'''
FileName:factory.py
Creator:王烨
Date:2010.5.23
'''
import twisted.internet.protocol
import handler

class Factory(twisted.internet.protocol.Factory):
    '''twisted框架中的协议工厂类'''
    def __init__(self, *services):
        self.protocol = handler.Handler#连接到来时初始化Protocol对象
        self.__services = {}
        for s in services:
            self.__services[s.GetDescriptor().name] = s
            
    def buildProtocol(self, addr):
        '''创建protocol对象时调用的方法'''
        p = self.protocol(self.__services)
        p.factory = self
        return p